<template>
  <div
    class="pagination-container"
  >
    <el-pagination
      small
      background
      :total="total"
      :current-page.sync="currentPage"
      :page-size.sync="pageSize"
      :page-sizes="[10, 50, 100, 200, 500, 1000]"
      layout="total, sizes, prev, pager, next, jumper, ->, slot"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      @prev-click="handlePreClick"
      @next-click="handleNextClick"
    />
  </div>
</template>

<script>
export default {
  name: 'Pagination',
  props: {
    gridApi: {
      type: Object,
      default: undefined
    },
    total: {
      type: Number,
      default: undefined
    },
    defaultPageSize: {
      type: Number,
      default: undefined
    }
  },
  data() {
    return {
      currentPage: 1,
      pageSize: this.defaultPageSize
    }
  },
  computed: {

  },
  methods: {
    handleSizeChange(limit) {
      this.gridApi.paginationSetPageSize(Number(limit))
      this.$emit('size-change', Number(limit))
    },
    handleCurrentChange(page) {
      this.gridApi.paginationGoToPage(Number(page) - 1)
      this.$emit('page-change', Number(page))
    },
    handlePreClick(page) {
      this.gridApi.paginationGoToPage(Number(page) - 1)
    },
    handleNextClick(page) {
      this.gridApi.paginationGoToPage(Number(page) - 1)
    },
    // API
    resetCurrentPage() {
      this.currentPage = 1
    }
  }
}
</script>

<style lang="scss" scoped>
.pagination-container {
  box-sizing: border-box;
  border-top: 0;
  margin: 0;
  height: 35px;
  align-items: center;
  display: flex;
  justify-content: flex-end;
  background-color: #fff;
  ::v-deep .el-input {
    .el-input__inner {
      height: 22px;
      line-height: 22px;
    }
  }
}
</style>
